import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  ApprovalFlowTemplateVO,
  ApprovalFlowTemplateForm,
  ApprovalFlowTemplateQuery,
  ApprovalInstanceUpdateForm,
  ApprovalAuditBo,
  ApprovalInstanceVo
} from '@/api/other/approval/types';

/**
 * 查询审核流程模板列表
 */
export const listApprovalFlowTemplate = (query?: ApprovalFlowTemplateQuery): AxiosPromise<ApprovalFlowTemplateVO[]> => {
  return request({
    url: '/approval/flowTemplate/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询审核流程模板详细信息
 */
export const getApprovalFlowTemplate = (id: string | number): AxiosPromise<ApprovalFlowTemplateVO> => {
  return request({
    url: '/approval/flowTemplate/' + id,
    method: 'get'
  });
};

/**
 * 新增审核流程模板
 */
export const addApprovalFlowTemplate = (data: ApprovalFlowTemplateForm) => {
  return request({
    url: '/approval/flowTemplate',
    method: 'post',
    data: data
  });
};

/**
 * 修改审核流程模板
 */
export const updateApprovalFlowTemplate = (data: ApprovalFlowTemplateForm) => {
  return request({
    url: '/approval/flowTemplate',
    method: 'put',
    data: data
  });
};

/**
 * 删除审核流程模板
 */
export const delApprovalFlowTemplate = (id: string | number | Array<string | number>) => {
  return request({
    url: '/approval/flowTemplate/' + id,
    method: 'delete'
  });
};

/**
 * 审核接口（推荐使用）
 */
export const audit = (data: ApprovalAuditBo) => {
  return request({
    url: '/approval/instance/audit',
    method: 'put',
    data: data
  });
};

/**
 * 更新审核实例状态
 */
export const updateApprovalInstance = (data: ApprovalInstanceUpdateForm) => {
  return request({
    url: '/approval/instance/update',
    method: 'put',
    data: data
  });
};

/**
 * 获取指定业务的审核流程展示信息
 */
export const displayApprovalFlow = (businessType: string, businessId: string | number): AxiosPromise<ApprovalInstanceVo> => {
  return request({
    url: '/approval/instance/display',
    method: 'get',
    params: {
      businessType,
      businessId
    }
  });
};
